
package com.haiyou.common.binary.reader;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

import com.haiyou.common.util.string.StringUtils;


/**
 * 
 * 
 * @Description: 二进制读取工具
 * @author xingyuan
 * @date 2022年2月15日 下午5:04:45
 */
public interface Reader {

	default String bytes2String(byte[] array, Charset charset) throws Exception {
		return StringUtils.bytes2String(array, charset);
	}

	default String bytes2UTF8(byte[] array) throws Exception {
		return bytes2String(array, StringUtils.UTF8);
	}

	ByteBuffer buffer();

	boolean hasRemaining();

	int remaining();

	int readByte();

	int readShort();

	int readInt();

	long readLong();

	float readFloat();

	double readDouble();

	boolean readBool();

	char readChar();

	String readString(Charset charset);

	default String readUTF8() {
		return readString(StringUtils.UTF8);
	}

	byte[] readBytes();

	short[] readShorts();

	int[] readInts();

	long[] readLongs();

	float[] readFloats();

	double[] readDoubles();

	boolean[] readBooleans();

	char[] readChars();

	String[] readStrings();

	Byte[] read$Bytes();

	Short[] read$Shorts();

	Integer[] read$Integers();

	Long[] read$Longs();

	Float[] read$Floats();

	Double[] read$Doubles();

	Boolean[] read$Booleans();

	Character[] read$Chars();

	<E> E readObject(Class<E> cls);

	/**
	 * 读取列表
	 * 
	 * @param cls    数据类型
	 * @param result 结果集
	 * @return 结果需要强转成自己所需的类型,比如List,Set
	 */
	<E> Collection<E> readCollection(Class<E> cls, Collection<E> result);

	<K, V> Map<K, V> readMap(Class<K> keyClazz, Class<V> valueClazz);

	Date readDate();

	Enum readEnum(Class enumClazz);

	<T> Class<T> readClazz(Class<T> cls);
}
